using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class DoctorScheduleMap : EntityTypeConfiguration<DoctorSchedule>
	{
		public DoctorScheduleMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.CreatedBy)
				.HasMaxLength(50);
				
			this.Property(t => t.ModifiedBy)
				.HasMaxLength(50);
				
			// Table & Column Mappings
			this.ToTable("DoctorSchedules");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.StartScheduleTime).HasColumnName("StartScheduleTime");
			this.Property(t => t.EndScheduleTime).HasColumnName("EndScheduleTime");
			this.Property(t => t.AllDay).HasColumnName("AllDay");
			this.Property(t => t.DaySet).HasColumnName("DaySet");
			this.Property(t => t.MinutePerSlot).HasColumnName("MinutePerSlot");
			this.Property(t => t.DoctorId).HasColumnName("DoctorId");
			this.Property(t => t.HospitalUnitId).HasColumnName("HospitalUnitId");
			this.Property(t => t.HospitalUnitRoomId).HasColumnName("HospitalUnitRoomId");
			this.Property(t => t.CreatedBy).HasColumnName("CreatedBy");
			this.Property(t => t.CreatedOn).HasColumnName("CreatedOn");
			this.Property(t => t.ModifiedBy).HasColumnName("ModifiedBy");
			this.Property(t => t.ModifiedOn).HasColumnName("ModifiedOn");
			this.Property(t => t.RecordStatus).HasColumnName("RecordStatus");

			// Relationships
			this.HasRequired(t => t.Doctor)
				.WithMany(t => t.DoctorSchedules)
				.HasForeignKey(d => d.DoctorId);
				
			this.HasOptional(t => t.HuRoom)
				.WithMany(t => t.DoctorSchedules)
				.HasForeignKey(d => d.HospitalUnitRoomId);
				
			this.HasOptional(t => t.RefHu)
				.WithMany(t => t.DoctorSchedules)
				.HasForeignKey(d => d.HospitalUnitId);
				
		}
	}
}

